package com.general.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.general.template.enums.ResultEnum;
import com.general.template.pojo.PowerJobs;
import com.general.template.service.PowerJobsService;
import com.general.template.utils.Result;
import com.general.template.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 杰哥
 * Date: 2021/2/16 17:41
 * @Description:
 **/
@RequestMapping("jobs")
@RestController
@Api(value="岗位管理",description = "用户对岗位的查看和修改")
public class JobsController {

    @Autowired
    private PowerJobsService powerJobsService;

    /**
     * 添加岗位
     *
     * @author 杰哥
     * @date 2021/2/16 17:51
     * @param job
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="addJob",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="添加岗位",notes = "添加岗位")
    public Result<Object> addJob(@RequestBody PowerJobs job){
        boolean save = this.powerJobsService.save(job);
        if (save){
            return new Result<>(ResultEnum.SUCCESS,"添加成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"添加失败!");
        }
    }

    /**
     * 修改岗位信息
     *
     * @author 杰哥
     * @date 2021/2/16 17:52
     * @param job
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="updateJob",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value="修改岗位",notes = "修改岗位")
    public Result<Object> updateJob(@RequestBody PowerJobs job){
        boolean save = this.powerJobsService.updateById(job);
        if (save){
            return new Result<>(ResultEnum.SUCCESS,"修改成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"修改失败!");
        }
    }

    /**
     * 管理查询全部岗位
     *
     * @author 杰哥
     * @date 2021/2/16 17:54
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="getList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="查询岗位",notes = "查询全部岗位")
    public Result<Object> getList(){
        List<PowerJobs> list = this.powerJobsService.list();
        return new Result<>(ResultEnum.SUCCESS,list);
    }

    /**
     * 前台查询
     *
     * @author 杰哥
     * @date 2021/2/16 19:08
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="pages",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="前台查询全部岗位",notes = "前台查询全部岗位")
    public Result<Object> pages(){
        List<PowerJobs> list = this.powerJobsService.list(new QueryWrapper<PowerJobs>().eq("status",0));
        return new Result<>(ResultEnum.SUCCESS,list);
    }

    /**
     * 禁用岗位
     *
     * @author 杰哥
     * @date 2021/2/16 18:03
     * @param id
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="禁用岗位",notes = "禁用岗位")
    public Result<Object> delete(@PathVariable("id") Integer id){
        PowerJobs jobs = new PowerJobs();
        jobs.setId(id);
        jobs.setStatus(1);
        boolean b = this.powerJobsService.updateById(jobs);
        if (b){
            return new Result<>(ResultEnum.SUCCESS,"禁用成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"禁用失败!");
        }
    }

    /**
     * 启用岗位
     *
     * @author 杰哥
     * @date 2021/2/16 18:04
     * @param id
     * @return com.general.template.utils.Result<java.lang.Object>
     */
    @RequestMapping(value="enable/{id}",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="启用岗位",notes = "启用岗位")
    public Result<Object> enable(@PathVariable("id") Integer id){
        PowerJobs jobs = new PowerJobs();
        jobs.setId(id);
        jobs.setStatus(0);
        boolean b = this.powerJobsService.updateById(jobs);
        if (b){
            return new Result<>(ResultEnum.SUCCESS,"启用成功!");
        }else{
            return new Result<>(ResultEnum.SUCCESS,"启用失败!");
        }
    }


}
